#include						"handler.h"
#include						"ASocket.h"

PacketHandler::PacketHandler(Processor &proc) : _proc(proc), _pkgBuff(20)
{
}

PacketHandler::~PacketHandler()
{
}

void							PacketHandler::harvest(ASocket *socket, byteArray *received)
{
	Packet						*packet = toPacket(received);
	packet->setFrom(socket->getIp().toString().toStdString());
	if (packet != NULL)
		_proc.interpret(packet);
	delete received;
}

Packet							*PacketHandler::toPacket(byteArray *data)
{
	Packet						*ret = new Packet;

	ret->init();
	ret->setData(data);
	return ret;
}